package br.com.vraptor.jpessoal.controllers;

import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vraptor.jpessoal.bean.Colaborador;
import br.com.vraptor.jpessoal.bean.ObjSession;

@Resource
public class PrincipalController {
     Result result;
     ColaboradorController colaboradorController;
     ObjSession objsession;
    
    
     
    public PrincipalController(Result result, ColaboradorController colaboradorController,ObjSession objsession){
        
        this.result = result;       
        this.colaboradorController = colaboradorController;
        this.objsession = objsession;
        
        
        
    }
    
  @Path("/principal")  
  public void index(){
      
      if (this.objsession.getSession() != null){      
      result.include("session",this.objsession.getSession());
      //result.include("ultimoColaborador",this.obterUltimo());
      }else{
          
          result.redirectTo(IndexController.class).index();
      }
      
  }  
    
  private Colaborador obterUltimo(){
  
      Colaborador colaborador = this.colaboradorController.obterUltimo();
      return colaborador;
  }
  
  @Path("principal/sair")
  public void sair(){
      
     
     this.objsession.invalidar();
     result.redirectTo(IndexController.class).index();
  }
  
}
